package com.riguz.springcloud.service;

import com.riguz.springcloud.exception.ResourceNotFoundException;
import com.riguz.springcloud.model.Post;
import com.riguz.springcloud.repository.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PostService {
    @Autowired
    private PostRepository postRepository;

    public Post findPostById(String id) {
        Post post = postRepository.findPostById(id);
        if (post == null)
            throw new ResourceNotFoundException("Post not found:" + id);
        return post;
    }
}
